import { reactive } from 'vue'

interface Notification {
  message: string
  active: boolean
}

const data = reactive<Notification>({
  message: '',
  active: false
})

export interface NotificationInfo {
  notification: Notification
  setNotification: (newMessage: string) => boolean
  toggleNotification: () => void
}

const useNotification = () => {
  const setNotification = (newMessage: string) => {
    data.message = newMessage
    return (data.active = true)
  }

  const toggleNotification = () => {
    data.active = !data.active
  }

  const notifaficationInfo: NotificationInfo = {
    notification: data,
    setNotification,
    toggleNotification
  }

  return notifaficationInfo
}

export default useNotification
